import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default {
  state: {
    menuList: [],
    permList: [],
    hasRoutes: false,
    editableTabsValue: "Index",
    editableTabs: [{ name: "首页", title: "首页" }],
  },
  mutations: {
    setMenuList(state, menus) {
      state.menuList = menus;
    },
    setPermList(state, perms) {
      state.permList = perms;
    },
    changeRouteStatus(state, hasRoutes) {
      state.hasRoutes = hasRoutes;
    },
    addTab(state, tab) {
      console.log("===================start");
      let index = state.editableTabs.findIndex((e) => {
        console.log(e.name, tab.name);
        return e.name === tab.name;
      });
      console.log(index);
      console.log("===================end");
      if (index === -1) {
        state.editableTabs.push({
          title: tab.title,
          name: tab.name,
        });
      }
      state.editableTabsValue = tab.name;
    },
    resetState: (state) => {
      state.menuList = [];
      state.permList = [];
      state.hasRoutes = false;
      state.editableTabsValue = "Index";
      state.editableTabs = [{ name: "首页", title: "首页" }];
    },
  },
  actions: {},
};
